﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AutoDeploy.Filters
{
    public class ExceptionFilter : Attribute, IExceptionFilter
    {
        private readonly ILogger<ExceptionFilter> _logger;
        public ExceptionFilter(ILogger<ExceptionFilter> logger)
        {
            _logger = logger;
        }
        public void OnException(ExceptionContext context)
        {
            if(!context.ExceptionHandled)
            {
                _logger.LogError(context.Exception.Message);
                context.Result = new JsonResult(new { code = 500, msg = "系统错误，请联系管理员！" });
                return;
            }
        }
    }
}
